#include "startwindow.h"
#include "ui_startwindow.h"

#include <QImage>
#include <QPushButton>
#include <gamelevel.h>
#include <mainwindow.h>

StartWindow::StartWindow(QWidget *parent) : QMainWindow(parent),
    ui(new Ui::StartWindow)
{
    setFixedSize(1680, 580);

    titleImage = new QLabel(this);
    titleImage->setFixedSize(910, 88);
    titleImage->move(385, 125);
    titleImage->setParent(this);
    titleImage->setScaledContents(true);
    auto pixmap = QPixmap(":img/img/title.png");
    pixmap.scaled(titleImage->size(), Qt::KeepAspectRatio);
    titleImage->setPixmap(pixmap);

    btnEasy = new QPushButton(this);
    btnEasy->setParent(this);
    btnEasy->setFixedSize(281, 75);
    btnEasy->move(209, 425);
    btnEasy->setStyleSheet("border-image:url(:/img/img/btn_easy.png);");

    btnMedium = new QPushButton(this);
    btnMedium->setParent(this);
    btnMedium->setFixedSize(281, 75);
    btnMedium->move(699, 425);
    btnMedium->setStyleSheet("border-image:url(:/img/img/btn_medium.png);");

    btnHard = new QPushButton(this);
    btnHard->setParent(this);
    btnHard->setFixedSize(281, 75);
    btnHard->move(1189, 425);
    btnHard->setStyleSheet("border-image:url(:/img/img/btn_hard.png);");

    connect(btnEasy, QPushButton::clicked, this, easyModeClicked);
    connect(btnMedium, QPushButton::clicked, this, mediumModeClicked);
    connect(btnHard, QPushButton::clicked, this, hardModeClicked);
    mainWindow = nullptr;
}

void StartWindow::easyModeClicked()
{
    delete mainWindow;
    mainWindow = new MainWindow(this, "{\n"
                                      "    \"player\": [9, 11],\n"
                                      "    \"data\": [\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,3,3,3,3,3,3,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,3,4,4,4,4,3,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,3,4,1,4,2,3,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,3,4,3,1,2,3,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,3,4,1,4,2,3,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,3,3,3,3,3,3,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\n"
                                      "    ]\n"
                                      "}");
    mainWindow->show();
}//这是EASY关卡的文档解析

void StartWindow::mediumModeClicked()
{
    delete mainWindow;
    mainWindow = new MainWindow(this, "{\n"
                                      "    \"player\": [11, 10],\n"
                                      "    \"data\": [\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,3,3,3,3,3,3,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,3,4,4,2,3,3,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,3,4,4,1,4,3,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,3,2,1,3,2,3,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,3,4,4,1,4,3,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,3,3,4,4,4,3,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,3,3,3,3,3,3,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\n"
                                      "    ]\n"
                                      "}");
    mainWindow->show();
}

void StartWindow::hardModeClicked()
{
    delete mainWindow;
    mainWindow = new MainWindow(this, "{\n"
                                      "    \"player\": [9,9],\n"
                                      "    \"data\": [\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,3,3,3,3,3,3,3,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,3,3,4,4,4,4,4,3,3,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,3,4,4,1,2,1,4,4,3,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,3,4,1,3,2,3,1,4,3,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,3,3,2,2,4,2,2,2,3,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,3,4,1,3,2,3,1,4,3,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,3,4,4,1,2,1,4,4,3,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,3,4,4,4,3,4,4,3,3,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n"
                                      "        [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\n"
                                      "    ]\n"
                                      "}");
    mainWindow->show();
}

StartWindow::~StartWindow()
{
    delete btnEasy;
    delete btnHard;
    delete btnMedium;
    delete titleImage;
    delete mainWindow;
}
